import request from "../../utils/http/index";
import {QueryRoleParams, RoleForm} from "./types/role.dto";
import type {ApiResponse} from "../../utils/ApiResponse";

//获取角色列表
export const getRoleList = (query: QueryRoleParams) => {
    return request({
        url: "/sysRole/info",
        method: "get",
        params: query,
    });
};

//新增
export const addRole = (data: RoleForm): Promise<ApiResponse<Object>> => {
    return request({
        url: "/sysRole/insert",
        data,
        method: "post",
    });
};

//更新
export const updateRole = (data: RoleForm): Promise<ApiResponse<Object>> => {
    return request({
        url: `/sysRolePermission/permissions/${data.id}`,
        data: data.menuIds,
        method: "post",
    });
};

//删除角色
export const deleteRole = (menuId: number | number[]) => {
    return request({
        url: `/role/deleteRole/${menuId}`,
        method: "delete",
    });
};

// 查询所有权限
export const getAllPermissions = (): Promise<ApiResponse<[]>> => {
    return request({
        url: "/sysRolePermission/permissions",
        method: "get",
    });
};

//根据角色id，查询权限
export const getRolePermission = (roleId: any): Promise<ApiResponse<[]>> => {
    return request({
        url: `/sysRolePermission/permissions/${roleId}`,
        method: "get",
    });
};
